package com.example.tianling.controller;

import com.example.tianling.common.annotation.Login;
import com.example.tianling.common.annotation.LoginUser;
import com.example.tianling.common.utils.R;
import com.example.tianling.common.vo.UserInfoVo;
import com.example.tianling.entity.UserEntity;
import com.example.tianling.entity.UserInfoEntity;
import com.example.tianling.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    @Login
    @PostMapping("/user_info")
    @ResponseBody
    public R getUserInfo(@LoginUser UserEntity user) {
        UserInfoEntity userInfo = userInfoService.getUserInfo(user.getUserId());
        UserInfoVo userInfoVo = new UserInfoVo(userInfo);

        // reward 可修改
        Map<String, Object> reward = new HashMap<>();
        reward.put("trainTicket", 3);
        reward.put("aiTicket", 3);

        userInfoVo.setReward(reward);

        return R.success(userInfoVo);
    }

    @Login
    @PostMapping("/user_info/get_reward")
    @ResponseBody
    public R getReward(@LoginUser UserEntity user) {
        return R.success(userInfoService.getReward(user.getUserId()));
    }
}
